<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="__ROOT__/Public/Admin/shortcut icon" href="favicon.ico">
	<link href="__ROOT__/Public/Admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
	<link href="__ROOT__/Public/Admin/css/animate.css" rel="stylesheet">
	<link href="__ROOT__/Public/Admin/css/style.css?v=4.1.0" rel="stylesheet">
	
	<link href="__ROOT__/Public/Admin/js/plugins/bootstrap-editable/css/bootstrap-editable.css" rel="stylesheet" />
	<link href="__ROOT__/Public/Admin/js/plugins/bootstrap221/css/editable.css" rel="stylesheet" />
	<link href="__ROOT__/Public/Admin/js/plugins/sweetalert/sweetalert.css" rel="stylesheet">
	
	<style>
.table > thead > tr > th, .table > tbody > tr > th, .table > tfoot > tr > th, .table > thead > tr > td, .table > tbody > tr > td, .table > tfoot > tr > td {
	height:35px;
}			
		.loading{
			 width: 35px;
			 height: 35px;
			 margin: 0 auto;
			 margin-top:100px;
			 position: fixed;
			 top: 0px;
			 left: 0px;
			 right: 0px;
			 bottom: 0px;
			 margin: auto;
		}
	</style>


</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox float-e-margins">
            <div class="ibox-content">
                <table class="table table-bordered table-striped text-center" data-mobile-responsive="true">
                    <thead>
                    </thead>
                    <tbody>
                    	
                        <tr style="background-color:#efd38a !important; text-align:left;" >
                            <td colspan="10">项目名称：<span id="projectName"></span></td>
                        </tr>
                        
						<tr style="background-color:#efd38a !important; text-align:left;" >
                            <td colspan="10">项目周期：<span id="projectCycle"></span></td>
                        </tr>
                        
                        <tr style="background-color:#efd38a !important; text-align:left;" >
                            <td colspan="10">项目负责人：<span id="ChargeUserName"></span></td>
                        </tr>
                        
                        <tr style="background-color:#efd38a !important; text-align:left;" >
                            <td colspan="10">项目组成员：<span id="projectMember"></span></td>
                        </tr>
                        
                        <tr style="background-color:#efd38a !important; text-align:left;" >
                            <td colspan="10">重要节点：<span id="ImportantPoint"></span></td>
                        </tr>
                        
                        <tr style="background-color:#305cf1 !important; color: #FFFFFF;" >
                            <td rowspan="2">项目周期</td>
                            <td colspan="3">总体情况</td>
                            <td rowspan="2">沟通/会面时间（根据实际情况记录）</td>
                            <td rowspan="2">沟通内容</td>
                            <td rowspan="2">项目方参与人员</td>
                            <td rowspan="2">业主方参与人员</td>
                            <td rowspan="2">成果文档及交付物</td>
                            <td rowspan="2">备注</td>
                        </tr>
                        <tr style="background-color:#305cf1 !important; color: #FFFFFF;">
                            <td>本周总结</td>
                            <td>下周计划</td>
                            <td>待解决问题</td>
                        </tr>
                        <tr id="toptr"></tr>
                        <tr style="background-color:#ececec;" id="">
							<td colspan="10" >  
								<a onclick="additem(this)">添加一条记录</a>
							</td>
						</tr>
                      
                        
                	</tbody>
          		</table>
            </div>
        </div>
    </div>
    <img src="__ROOT__/Public/Admin/img/loading.gif" class="loading" style="display:none;">	
</body>
<script src="__ROOT__/Public/Admin/js/jquery.min.js"></script>
<script src="__ROOT__/Public/Admin/js/plugins/laydate/laydate.js"></script>
<script src="__ROOT__/Public/Admin/js/plugins/bootstrap221/js/bootstrap.min.js"></script>
<script src="__ROOT__/Public/Admin/js/plugins/bootstrap-editable/js/bootstrap-editable.js"></script>
<script src="__ROOT__/Public/Admin/js/plugins/sweetalert/sweetalert.min.js"></script>
	
<link href="__ROOT__/Public/Admin/css/selector/selectorstyle.css" rel="stylesheet"/>
<script src="__ROOT__/Public/Admin/js/plugins/selector/selector.js"></script>
<script src="__ROOT__/Public/Admin/js/plugins/selector/jquery.ztree.all.js"></script>
<script>
	
	var j = 0;
	var projectID = 0;
	<?php if(!empty($id)){echo "projectID = ".$id.";";}?>
	var itmeHtml = "";
	var trLength = 0;
	tableGetData();
	
	function tableGetData(){
		$(".loading").show();
		$.post("<?=U('Admin/ProjectWeekreport/save',array('type'=>'table','id'=>$id))?>",{},function(result){
			data = result;
			$("#projectName").html(data.projectName);
			$("#projectCycle").html(data.projectCycle+"天");
			$("#ChargeUserName").html(data.ChargeUserName);
			$("#projectMember").html(data.projectMember);
			$("#ImportantPoint").html(data.ImportantPoint);
			for(var list in data.data){
				j++;
				itmeHtml = "<tr commid="+data.data[list].commID+" id="+data.data[list].ID+" style=\"background-color:#FFFFFF\"><td width='110'>"+data.data[list].cycle+"<p style='font-size:12px;'>（<span class='cycleDate"+j+" '>"+data.data[list].cycleDate+"</span>）</p></td><td><div class='WeekContent"+j+" myeditable'>"+data.data[list].WeekContent+"</div></td><td><div class='Plan"+j+" myeditable'>"+data.data[list].Plan+"</div></td><td><div class='Question"+j+" myeditable'>"+data.data[list].Question+"</div></td><td width='100'><div class='ComTime"+j+" myeditable'>"+data.data[list].ComTime+"</div></td><td><div class='ComContent"+j+" myeditable'>"+data.data[list].ComContent+"</div></td><td><div class='ProjectMember"+j+" myeditable'>"+data.data[list].ProjectMember+"</div></td><td><div class='CustomMember"+j+" myeditable'>"+data.data[list].CustomMember+"</div></td><td><div class='OutputContent"+j+" myeditable'>"+data.data[list].OutputContent+"</div></td><td><div class='Memo"+j+" myeditable'>"+data.data[list].Memo+"</div></td></tr>";
				$("#toptr").before(itmeHtml);
				TieEvent();
				trLength = data.data[list].NEWID;
			}
			$(".loading").hide();
		});
	}

		
		function additem(dom){
			j++;
			var cycle = Arabia_To_SimplifiedChinese(trLength + 1);
			var cycleDate = getNowFormatDate("date")+" ~ "+getNowFormatDate("date");
			var ComTime = getNowFormatDate("time");
			var newhtml = "<tr style=\"background-color:#FFFFFF\"><td class=\'\' width=\'110\'>第"+cycle+"周<p style=\'font-size:12px;\'>(<span class='cycleDate"+j+" '>"+cycleDate+"</span>)</p></td><td><div class='WeekContent"+j+" myeditable'></div></td><td><div class='Plan"+j+" myeditable'></div></td><td><div class='Question"+j+" myeditable'></div></td><td><div class='ComTime"+j+" myeditable'>"+ComTime+"</div></td><td><div class='ComContent"+j+" myeditable'></div></td><td><div class='ProjectMember"+j+" myeditable'></div></td><td><div class='CustomMember"+j+" myeditable'></div></td><td><div class='OutputContent"+j+" myeditable'></div></td><td><div class='Memo"+j+" myeditable'></div></td></tr>";
		  	$(dom).parent().parent().before(newhtml);
	     	$(dom).text("点击保存");
		 	$(dom).attr('onclick', '');
			$(dom).attr('onclick', "tableAddData(this)");
			TieEvent();
		}
		
		function tableAddData(dom){
	 		var tr = $(dom).parent().parent().prev().children();
	 		week = {
	 			"ProjectID" : projectID,
	 			"allDate" : $(tr).find("span").text(),
	 			"Content" : $(tr[1]).text(),
	 			"Plan" : $(tr[2]).text(),
	 			"Question" : $(tr[3]).text()
	 		};
	 		comm = {
	 			"ComTime" : $(tr[4]).text(),
	 			"Content" : $(tr[5]).text(),
	 			"ProjectMember" : $(tr[6]).text(),
	 			"CustomMember" : $(tr[7]).text(),
	 			"OutputContent" : $(tr[8]).text(),
	 			"Memo" : $(tr[9]).text()
	 		};
	 		$.post("{:U('Admin/ProjectWeekreport/setTableData')}",{'week':week,'comm':comm},function(result){
			    if (result.status) {
			    	 swal({
			            title: "继续操作？",
			            text: "操作成功！",
			            type: "success",
			            showCancelButton: false,
			            confirmButtonColor: "#DD6B55",
			            confirmButtonText: "确认",
			            cancelButtonText: "",
			            closeOnConfirm: false,
			            closeOnCancel: false
			       },function (isConfirm) {
			            document.location.reload();
			       });			
			    }else{
			    	swal("提示", result.info, "error");
			    }
			});
	 	};
 	
		function TieEvent(){
			  laydate.render({
	            elem: '.cycleDate'+j
	            ,type: 'date'
				,theme: 'molv'
	            ,range: '~'
	            ,change: function(value, date, endDate){
	            },done:function(value,date){
					var tr = $(this.elem).parent().parent().parent();
		            if($(tr).attr("id") == undefined) return;
		            var timeid = $(tr).attr("id");
		 			var updatedata = {
			 			"allDate": value,
						"ID": timeid
		 			}
	 				tableUpdate(updatedata,'w');
				}
	          });
	        
	        laydate.render({
			  elem: '.ComTime'+j
			  ,theme: 'molv'
			  ,type: 'datetime'
			  ,done:function(value,date){
					var tr = $(this.elem).parent().parent();
		            if($(tr).attr("id") == undefined) return;
		            var timeid = $(tr).attr("commid");
		 			var updatedata = {
			 			"ComTime": value,
						"ID": timeid
		 			}
	 				tableUpdate(updatedata,'c');
			   }
			});
			
	        $(".ProjectMember"+j).editable({
	            type: "text", 
	            title: "项目方参与人员",
	            disabled: false, 
	            emptytext: "",
	            //mode: "inline",
				url : function(params) {  
	               //console.info(params);
	            },
	            validate: function (value) { //字段验证
	                if (!$.trim(value)) {
	                    return '不能为空';
	                }else{
	                	var tr = $(this).parent().parent();
	                	if($(tr).attr("id") == undefined) return;
	                	var timeid = $(tr).attr("commid");
	 					var updatedata = {
			 				"ProjectMember": value,
			 				"ID": timeid
			 			}
	 					tableUpdate(updatedata,'c');
	                }
	            }
	        });
        
        	$(".CustomMember"+j).editable({
	            type: "text", 
	            title: "业主方参与人员",
	            disabled: false, 
	            emptytext: "",
	            //mode: "inline",
				url : function(params) {  
	               //console.info(params);
	            },
	            validate: function (value) { //字段验证
	                if (!$.trim(value)) {
	                    return '不能为空';
	                }else{
	                	var tr = $(this).parent().parent();
	                	if($(tr).attr("id") == undefined) return;
	                	var timeid = $(tr).attr("commid");
	 					var updatedata = {
			 				"CustomMember": value,
			 				"ID": timeid
			 			}
	 					tableUpdate(updatedata,'c');
	                }
	            }
	        });
	        
	        $('.WeekContent'+j).editable({ 
	            type: "textarea",             
	            title: "本周总结",           
	            disabled: false,           
	            emptytext: "",
	            mode: "popup",          
	            validate: function (value) { //字段验证
	                if (!$.trim(value)) {
	                    return '不能为空';
	                }else{
	                	var tr = $(this).parent().parent();
	                	if($(tr).attr("id") == undefined) return;
	                	var timeid = $(tr).attr("id");
	 					var updatedata = {
			 				"Content": value,
			 				"ID": timeid
			 			}
	 					tableUpdate(updatedata,'w');
	                }
	            }
	     	});
	     	
	     	$('.Plan'+j).editable({
	            type: "textarea",             
	            title: "下周计划",           
	            disabled: false,           
	            emptytext: "",
	            mode: "popup",          
	            validate: function (value) { //字段验证
	                if (!$.trim(value)) {
	                    return '不能为空';
	                }else{
	                	var tr = $(this).parent().parent();
	                	if($(tr).attr("id") == undefined) return;
	                	var timeid = $(tr).attr("id");
	 					var updatedata = {
			 				"Plan": value,
			 				"ID": timeid
			 			}
	 					tableUpdate(updatedata,'w');
	                }
	            }
	     	});
	     	
	     	$('.Question'+j).editable({
	            type: "textarea",             
	            title: "待解决问题",           
	            disabled: false,           
	            emptytext: "",
	            mode: "popup",          
	            validate: function (value) { //字段验证
	                if (!$.trim(value)) {
	                    return '不能为空';
	                }else{
	                	var tr = $(this).parent().parent();
	                	if($(tr).attr("id") == undefined) return;
	                	var timeid = $(tr).attr("id");
	 					var updatedata = {
			 				"Question": value,
			 				"ID": timeid
			 			}
	 					tableUpdate(updatedata,'w');
	                }
	            }
	     	});
	     	
	     	$('.ComContent'+j).editable({
	            type: "textarea",             
	            title: "沟通内容",           
	            disabled: false,           
	            emptytext: "",
	            mode: "popup",          
	            validate: function (value) { //字段验证
	                if (!$.trim(value)) {
	                    return '不能为空';
	                }else{
	                	var tr = $(this).parent().parent();
	                	if($(tr).attr("id") == undefined) return;
	                	var timeid = $(tr).attr("commid");
	 					var updatedata = {
			 				"Content": value,
			 				"ID": timeid
			 			}
	 					tableUpdate(updatedata,'c');
	                }
	            }
	     	});
	     	
	     	
	     	$('.OutputContent'+j).editable({
	            type: "textarea",             
	            title: "成果文档及交付物",           
	            disabled: false,           
	            emptytext: "",
	            mode: "popup",          
	            validate: function (value) { //字段验证
	                if (!$.trim(value)) {
	                    return '不能为空';
	                }else{
	                	var tr = $(this).parent().parent();
	                	if($(tr).attr("id") == undefined) return;
	                	var timeid = $(tr).attr("commid");
	 					var updatedata = {
			 				"OutputContent": value,
			 				"ID": timeid
			 			}
	 					tableUpdate(updatedata,'c');
	                }
	            }
	     	});
	     	
	     	$('.Memo'+j).editable({
	            type: "textarea",             
	            title: "备注",           
	            disabled: false,           
	            emptytext: "",
	            mode: "popup",          
	            validate: function (value) { //字段验证
	                if (!$.trim(value)) {
	                    return '不能为空';
	                }else{
	                	var tr = $(this).parent().parent();
	                	if($(tr).attr("id") == undefined) return;
	                	var timeid = $(tr).attr("commid");
	 					var updatedata = {
			 				"Memo": value,
			 				"ID": timeid
			 			}
	 					tableUpdate(updatedata,'c');
	                }
	            }
	     	});
		}
		

		function tableUpdate(updatedata,type){
			$(".loading").show();
	 		$.post("{:U('Admin/ProjectWeekreport/updateTableData')}&type="+type,updatedata,function(result){
	 			$(".loading").hide();
	 			if (result.status) {
			       swal("提示", result.info, "success");
			    }else{
			    	swal({
			            title: "",
			            text: "修改失败 "+result.info,
			            type: "error",
			            showCancelButton: false,
			            confirmButtonColor: "#DD6B55",
			            confirmButtonText: "确认",
			            cancelButtonText: "",
			            closeOnConfirm: false,
			            closeOnCancel: false
			        },function (isConfirm) {
			            document.location.reload();
			        });		
			    }
	 		});
		}
		
		
		function Arabia_To_SimplifiedChinese(Num) {
		    for (i = Num.length - 1; i >= 0; i--) {
		        Num = Num.replace(",", "")//替换Num中的“,”
		        Num = Num.replace(" ", "")//替换Num中的空格
		    }    
		    if (isNaN(Num)) { //验证输入的字符是否为数字
		        //alert("请检查小写金额是否正确");
		        return;
		    }
		    //字符处理完毕后开始转换，采用前后两部分分别转换
		    part = String(Num).split(".");
		    newchar = "";
		    //小数点前进行转化
		    for (i = part[0].length - 1; i >= 0; i--) {
		        if (part[0].length > 10) {
		            //alert("位数过大，无法计算");
		            return "";
		        }//若数量超过拾亿单位，提示
		        tmpnewchar = ""
		        perchar = part[0].charAt(i);
		        switch (perchar) {
		            case "0":  tmpnewchar = "零" + tmpnewchar;break;
		            case "1": tmpnewchar = "一" + tmpnewchar; break;
		            case "2": tmpnewchar = "二" + tmpnewchar; break;
		            case "3": tmpnewchar = "三" + tmpnewchar; break;
		            case "4": tmpnewchar = "四" + tmpnewchar; break;
		            case "5": tmpnewchar = "五" + tmpnewchar; break;
		            case "6": tmpnewchar = "六" + tmpnewchar; break;
		            case "7": tmpnewchar = "七" + tmpnewchar; break;
		            case "8": tmpnewchar = "八" + tmpnewchar; break;
		            case "9": tmpnewchar = "九" + tmpnewchar; break;
		        }
		        switch (part[0].length - i - 1) {
		            case 0: tmpnewchar = tmpnewchar; break;
		            case 1: if (perchar != 0) tmpnewchar = tmpnewchar + "十"; break;
		            case 2: if (perchar != 0) tmpnewchar = tmpnewchar + "百"; break;
		            case 3: if (perchar != 0) tmpnewchar = tmpnewchar + "千"; break;
		            case 4: tmpnewchar = tmpnewchar + "万"; break;
		            case 5: if (perchar != 0) tmpnewchar = tmpnewchar + "十"; break;
		            case 6: if (perchar != 0) tmpnewchar = tmpnewchar + "百"; break;
		            case 7: if (perchar != 0) tmpnewchar = tmpnewchar + "千"; break;
		            case 8: tmpnewchar = tmpnewchar + "亿"; break;
		            case 9: tmpnewchar = tmpnewchar + "十"; break;
		        }
		        newchar = tmpnewchar + newchar;
		    }   
		    //替换所有无用汉字，直到没有此类无用的数字为止
		    while (newchar.search("零零") != -1 || newchar.search("零亿") != -1 || newchar.search("亿万") != -1 || newchar.search("零万") != -1) {
		        newchar = newchar.replace("零亿", "亿");
		        newchar = newchar.replace("亿万", "亿");
		        newchar = newchar.replace("零万", "万");
		        newchar = newchar.replace("零零", "零");      
		    }
		    //替换以“一十”开头的，为“十”
		    if (newchar.indexOf("一十") == 0) {
		        newchar = newchar.substr(1);
		    }
		    //替换以“零”结尾的，为“”
		    if (newchar.lastIndexOf("零") == newchar.length - 1) {
		        newchar = newchar.substr(0, newchar.length - 1);
		    }
		    return newchar;
		}
		
		
		function getNowFormatDate(type) {
		    var date = new Date();
		    var seperator1 = "-";
		    var seperator2 = ":";
		    var month = date.getMonth() + 1;
		    var strDate = date.getDate();
		    if (month >= 1 && month <= 9) {
		        month = "0" + month;
		    }
		    if (strDate >= 0 && strDate <= 9) {
		        strDate = "0" + strDate;
		    }
		    if(type == "date"){
		    	var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
		    }else if(type == "time"){
		    	var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
		            + " " + date.getHours() + seperator2 + date.getMinutes()
		            + seperator2 + date.getSeconds();
		    }		    
		    return currentdate;
		}
</script>

</html>